<template>
  <div class="screen-right">
    <nanning-screen-border-box :bg-img="bgImg">
      <screen-title>查询列表</screen-title>
      <div class="screen-right-content">
        <!-- <nanning-screen-search placeholder-value="请输入公交线路"></nanning-screen-search> -->
        <div class="total-num">共{{queryList.length}}条数据</div>
        <div class="query-list">
          <div :class="['list-item', currentItem === index ? 'active' : '']" v-for="(item, index) in queryList" :key="index" @click="chooseItem(index)">
            <div class="city">{{item.name}}</div>
            <div class="detail">
              <div class="detail-item" v-for="(detail, order) in item.detailList" :key="order">
                <div class="label">{{detail.label}}：</div>
                <div class="value">{{detail.value}}</div>
              </div>
            </div>
          </div>
          <screen-load-more :loadMoreVisible="loadMoreVisible" :loadMoreType="loadMoreType"></screen-load-more>
        </div>
      </div>
    </nanning-screen-border-box>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { getPoliceMap } from 'api/situationAwareness/serviceForce/screenCenter'
enum LoadMoreType {
  none = 'none',
  loading = 'loading',
}
@Component({
  name: 'screen-right'
})

export default class ScreenRight extends Vue {
  private bgImg: string = require('assets/images/situational-awareness/security-left-border.png')

  private currentItem: string | number = ''

  private loadMoreVisible = false
  private loadMoreType: LoadMoreType = LoadMoreType.none

  private queryList: any[] = []

  created () {
    this.getPoliceMap()
  }

  mounted() {
    this.onReachBottom()
  }

  beforeDestroy() {
    this.removeReachBottom()
  }

  // 获取地图扎点数据
  getPoliceMap () {
    const params = {
      dzcode: ''
    }
    getPoliceMap(params).then(res => {
      console.log('勤务力量-地图打点数据', res)
      res.data.forEach((item: any) => {
        this.queryList.push({
          name: item.qwllXm, detailList: [{ label: '类型', value: item.qwllLxmc }, { label: '警号', value: item.jybh }]
        })
      })
    }).catch(err => {
      console.error('勤务力量-地图打点数据', err)
    })
  }

  // 选择客运站
  chooseItem(index: number) {
    this.currentItem = index
  }

  // 触底检测
  onReachBottom() {
    // @ts-ignore
    document.querySelector('.query-list').addEventListener('scroll', this.reachBottomCb.bind(this))
  }

  // 移除触底检测
  removeReachBottom() {
    // @ts-ignore
    document.querySelector('.query-list').removeEventListener('scroll', this.reachBottomCb.bind(this))
  }

  // 触底检测回调函数
  reachBottomCb(e: any) {
    const { scrollHeight, scrollTop, clientHeight } = e.target
    if (clientHeight + scrollTop >= scrollHeight) {
      this.loadMoreVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
.screen-right {
  width: 25.47%;
  height: 87.13%;
  position: absolute;
  z-index: 100;
  top: 0;
  right: 0;
  &-content {
    width: 100%;
    height: calc(100% - 50px);
    box-sizing: border-box;
    padding: 15px 24px 18px 22px;
    .total-num {
      width: 100%;
      height: 4em;
      line-height: 56px;
      font-size: 14px;
      font-family: 'PingFang Regular';
      font-weight: 400;
      color: rgba(255, 255, 255, 0.67);
      margin-top: 10px;
      text-indent: 20px;
    }
    .query-list {
      width: 100%;
      height: calc(100% - 10px - 56px);
      overflow-y: auto;
      &::-webkit-scrollbar {
        /*滚动条整体样式*/
        width: 6px; /*高宽分别对应横竖滚动条的尺寸*/
        height: 1px;
      }
      &::-webkit-scrollbar-thumb {
        /*滚动条里面小方块*/
        border-radius: 10px;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        background: #114da7;
      }
      &::-webkit-scrollbar-track {
        /*滚动条里面轨道*/
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        border-radius: 10px;
        background: #061836;
      }
      .list-item {
        width: 100%;
        box-sizing: border-box;
        padding: 0 20px;
        background: rgba(16, 75, 164, 0.22);
        border-radius: 2px;
        cursor: pointer;
        .city {
          width: 100%;
          height: 42px;
          display: flex;
          align-items: center;
          font-size: 18px;
          font-family: 'PingFang Regular';
          font-weight: 400;
          color: #ffffff;
          border-bottom: 1px dashed #8398d9;
        }
        .detail {
          width: 100%;
          display: grid;
          grid-template-columns: repeat(2, 1fr);
          padding: 6px 0;
          .detail-item {
            width: 100%;
            line-height: 28px;
            display: flex;
            align-items: center;
            .label {
              font-size: 16px;
              font-family: 'PingFang Regular';
              font-weight: 400;
              color: rgba(255, 255, 255, 0.67);
            }
            .value {
              font-size: 16px;
              font-family: 'PingFang Regular';
              font-weight: 400;
              color: #8da5eb;
            }
          }
        }
        & + .list-item {
          margin-top: 6px;
        }
        &.active {
          box-shadow: 0px 0px 15px 9px #2235b6 inset;
        }
      }
    }
  }
}
</style>
